﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Automted_Bank_teller
{
    public partial class WithdrawlsForm : Form
    {
        public WithdrawlsForm()
        {
            InitializeComponent();
        }

        private void BTN_Client_withdrawlsMoney_Confirm_Click(object sender, EventArgs e)
        {
            try
            {

                if (txtbox_client_withdrawlsMoney.Text.Length > 0)
                {

                    Withdrawls_Logic clnt_MoneyWithdrawls = new Withdrawls_Logic();
                    clnt_MoneyWithdrawls.WithdrawlsMoney_input_ByClient(float.Parse(txtbox_client_withdrawlsMoney.Text));


                    Withdrawls_Logic complete_withdrawls = new Withdrawls_Logic();
                    complete_withdrawls.Database_ConnectString();
                    complete_withdrawls.Open_Database();
                    complete_withdrawls.SelectCurrentBalance();
                    complete_withdrawls.GetCurrentBalance();
                    complete_withdrawls.MoneyAfterWirhdrawals();
                    complete_withdrawls.Close_Database();
                    //////
                    if (global_var.G_Current_Account_balance >= float.Parse(txtbox_client_withdrawlsMoney.Text))
                    {
                        complete_withdrawls.Open_Database();
                        complete_withdrawls.UpdateAccountBalaceAfterWithdrawls();
                        complete_withdrawls.ExecuteQuery();
                        complete_withdrawls.Close_Database();
                        MessageBox.Show("Successful Process");
                       
                    }
                         

                    else
                    {
                        MessageBox.Show("Sorry,You don't have enough money to do this Withdrawls transaction ");
                    }
                    

                }
                else
                {
                    MessageBox.Show("Error Entey, Empty fields Not Allowd!");
                }
            }catch(Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }

        }

        private void BTN_Client_withdrawlsMoney_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtbox_client_withdrawlsMoney_KeyPress(object sender, KeyPressEventArgs e)
        {
            char c = e.KeyChar;
            if (!char.IsDigit(c))
            {
                e.Handled = true;
                MessageBox.Show("Letters Not Allowed.");
            }
        }

        
    }
}
